package com.lee.dutylower.task;


import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.SystemClock;

import com.lee.dutylower.MyApplication;
import com.lee.dutylower.db.greenEntity.DutySoldierRecord;
import com.lee.dutylower.db.greenEntity.PostRecord;
import com.lee.dutylower.db.greenEntity.Sentry;
import com.lee.dutylower.db.greenEntity.Soldier;
import com.lee.dutylower.db.greenEntity.Squad;
import com.lee.dutylower.db.greenEntity.SquadRecord;
import com.lee.dutylower.db.greenEntity.Times;
import com.lee.dutylower.db.greendao.DutySoldierRecordDao;
import com.lee.dutylower.db.greendao.PostRecordDao;
import com.lee.dutylower.db.greendao.SentryDao;
import com.lee.dutylower.db.greendao.SoldierDao;
import com.lee.dutylower.db.greendao.SquadRecordDao;
import com.lee.dutylower.db.greendao.TimesDao;
import com.lee.dutylower.domain.DutySoldierRecordComparator;
import com.lee.dutylower.domain.SentryTypeEnum;
import com.lee.dutylower.domain.SoldierCharacter;
import com.lee.dutylower.domain.SoldierComparator;
import com.lee.dutylower.domain.SoldierInUseEnum;
import com.lee.dutylower.domain.SquadTypeEnum;
import com.lee.dutylower.utils.LogUtils;
import com.lee.dutylower.utils.ToastUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by lijie on 2017/7/31.
 */

public class NScheduleTask extends AsyncTask<Void, String, Void> {
    private ProgressDialog mProgressDialog = null;
    private Activity context;
    private PostRecordDao postRecordDao;
    private SquadRecordDao squadRecordDao;
    private SoldierDao soldierDao;
    private SentryDao sentryDao;
    private TimesDao timesDaoDao;
    private Handler handler;
    private int dayofweek;
    private boolean hasRest = true;

    private List<Times> timesList;
    //上午班全是一个人的哨位
    private List<Sentry> sentries_45;
    //一个半小时一个人的哨位
    private List<Sentry> sentries_15;
    //白天一个人的哨位 值班版专属
    private List<Sentry> sentries_90;
    //上岗班集合
    private List<SquadRecord> onTypeSquad;
    //值班版集合
    private List<SquadRecord> dutyTypeSquad;
    //补岗班集合
    private List<SquadRecord> restTypeSquad;

    //派位表集合
    private List<PostRecord> postRecordDBs;

    //数据库各个上岗班
    private Squad squadOn1;
    private Squad squadOn2;
    private Squad squadOn3;

    //值班版、补岗班
    private Squad squadRest;
    private Squad squadDuty;

    //一个半小时哨位上午人员分配集合
    private LinkedList<Soldier> soldier_Morning_1_15;
    private LinkedList<Soldier> soldier_Morning_2_15;
    private DutySoldierRecordDao dutySoldierDao;

    public NScheduleTask(Activity context, Handler handler, int dayofweek) {
        this.context = context;
        this.handler = handler;
        this.dayofweek = dayofweek;

        //初始化集合
        soldier_Morning_1_15 = new LinkedList<>();
        soldier_Morning_2_15 = new LinkedList<>();
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        postRecordDao = MyApplication.getApplication().getDaoSession().getPostRecordDao();
        squadRecordDao = MyApplication.getApplication().getDaoSession().getSquadRecordDao();
        soldierDao = MyApplication.getApplication().getDaoSession().getSoldierDao();
        sentryDao = MyApplication.getApplication().getDaoSession().getSentryDao();
        timesDaoDao = MyApplication.getApplication().getDaoSession().getTimesDao();
        dutySoldierDao = MyApplication.getApplication().getDaoSession().getDutySoldierRecordDao();

        mProgressDialog = new ProgressDialog(context);
        // 设置进度条风格，风格为圆形，旋转的
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

        // 设置ProgressDialog 提示信息
        mProgressDialog.setMessage("正在准备数据，请稍等。。。");

        // 设置ProgressDialog 的进度条是否不明确
        mProgressDialog.setIndeterminate(false);
        // 设置ProgressDialog 是否可以按退回按键取消
        mProgressDialog.setCancelable(false);
        mProgressDialog.show();

        //读取所有的时间段
        timesList = timesDaoDao.queryBuilder().build().list();
        //数据库读取相关类型的哨位

        sentries_45 = sentryDao.queryBuilder()
                .where(SentryDao.Properties.Sentry_type.eq(SentryTypeEnum.THREE_QUARTER.getType()))
                .build().list();
        sentries_15 = sentryDao.queryBuilder()
                .where(SentryDao.Properties.Sentry_type.eq(SentryTypeEnum.QUARTER.getType()))
                .build().list();
        sentries_90 = sentryDao.queryBuilder()
                .where(SentryDao.Properties.Sentry_type.eq(SentryTypeEnum.NINE_QUARTER.getType()))
                .build().list();
        //读取三种班次对应的班级

        onTypeSquad = squadRecordDao.queryBuilder()
                .where(SquadRecordDao.Properties.SquadType.eq(SquadTypeEnum.OnSquad.getType()))
                .build().list();
        dutyTypeSquad = squadRecordDao.queryBuilder()
                .where(SquadRecordDao.Properties.SquadType.eq(SquadTypeEnum.DutySquad.getType()))
                .build().list();
        restTypeSquad = squadRecordDao.queryBuilder()
                .where(SquadRecordDao.Properties.SquadType.eq(SquadTypeEnum.RestSquad.getType()))
                .build().list();

        //集合顺序调整
        LinkedList<SquadRecord> linkedList = new LinkedList<>();
        linkedList.addAll(onTypeSquad);
        for (int i = 1; i < dayofweek; i++) {
            SquadRecord last = linkedList.pollLast();
            linkedList.addFirst(last);
        }

        //遍历获取上岗班每个班
        squadOn1 = linkedList.get(0).getSquad();
        squadOn1.resetSoldiers();
        squadOn2 = linkedList.get(1).getSquad();
        squadOn2.resetSoldiers();
        squadOn3 = linkedList.get(2).getSquad();
        squadOn3.resetSoldiers();

        //获取值班版人员集合
        squadDuty = dutyTypeSquad.get(0).getSquad();
        squadDuty.resetSoldiers();

        //如果没有补岗班 标志设为false
        if (restTypeSquad == null || restTypeSquad.size() == 0) {
            hasRest = false;
        }

        if (hasRest) {
            //获取补岗班每个班的人员集合
            squadRest = restTypeSquad.get(0).getSquad();
            squadRest.resetSoldiers();
        }
    }

    @Override
    protected void onProgressUpdate(String... values) {
        super.onProgressUpdate(values);
        switch (values[1]){
            case "ok":
                mProgressDialog.setMessage(values[0]);
                break;
            case "finish":
                mProgressDialog.setMessage(values[0]);
                if (dayofweek == 7){
                    handler.sendEmptyMessage(1);
                }else {
                    handler.sendEmptyMessage(0);
                }
                mProgressDialog.cancel();
                break;
            case "err":
                mProgressDialog.setMessage(values[0]);
                ToastUtils.showShort(context,values[0]);
                mProgressDialog.cancel();
                break;
        }
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
        mProgressDialog.cancel();
    }

    @Override
    protected Void doInBackground(Void... voids) {
        if (dayofweek == 1){
            postRecordDao.deleteAll();
        }

        /**
         * 值班班相关处理
         */
        //先从值班班选（将值班班长班长选入6到8的607、选303、白302、夜302）
        long squadDutyId = squadDuty.getSuqadId();//取得值班班级ID
        Sentry sentry = sentryDao.queryBuilder()
                .where(SentryDao.Properties.Sentry_id.eq(11l))
                .build().unique();
        Times times = timesDaoDao.queryBuilder()
                .where(TimesDao.Properties.TimeID.eq(8l))
                .build().unique();
        chooseSoldierForDutyIn607(squadDutyId, sentry, times);

        //对哨位是全天类的进行遍历排序 选着对象是值班版人员
        for (Sentry sentryDB : sentries_90) {
            //遍历每一个时间段，按时间顺序进行排序
            for (Times timesDB : timesList) {
                //时间段7：30-9：00 给哨位类型90 安排人员
                if (timesDB.getTimeID() == 1) {
                    chooseSoldierForDutyIn302(squadDutyId, sentryDB, timesDB);
                }
                if (timesDB.getTimeID() == 2 && sentryDB.getSentry_name().equals("302")) {
                    chooseSoldierForDutyIn302(squadDutyId, sentryDB, timesDB);
                }
            }
        }

        publishProgress("值班班排序完成","ok");
        LogUtils.e("NScheduleTask","值班班排序完成");
        /**
         * 上岗班选人处理
         */
        //先验证是否人员是否够用
        boolean enough15 = true;
        boolean enough45 = true;

        if (dayofweek == 1){
            enough15 = checkSoldierForSentry(sentries_15, 15);
            enough45 = checkSoldierForSentry(sentries_45, 45);
        }

        publishProgress("人员校验完成","ok");
        LogUtils.e("NScheduleTask","人员校验完成 enough15"+enough15+" enough45"+enough45);

        boolean enough;
        if (enough15 && enough45) {
            enough = true;
        } else {
            enough = false;
        }
        if (enough) {
            //对哨位是15的进行遍历排序 先进行 1-3
            for (int i = 0; i < sentries_15.size(); i++) {
                Sentry sentryDB = sentries_15.get(i);
                if (sentryDB.getSentry_id() == 2l) {//监护503
                    chooseSoldierForSentry15In123(sentryDB, soldier_Morning_1_15);
                }
                if (sentryDB.getSentry_id() == 8l) {//监护603
                    chooseSoldierForSentry15In123(sentryDB, soldier_Morning_2_15);
                }
            }
            // 4-9 进行选人 利用1-3的人员
            for (Sentry sentry1 : sentries_15) {
                if (sentry1.getSentry_id() == 2l) {//监护503
                    chooseSoldierForSentry15In429(sentry1, soldier_Morning_1_15, soldier_Morning_2_15);
                }
                if (sentry1.getSentry_id() == 8l) {//监护603
                    chooseSoldierForSentry15In429(sentry1, soldier_Morning_2_15, soldier_Morning_1_15);
                }
            }

            publishProgress("对哨位是一个半小时类型排序时间1-9","ok");
            LogUtils.e("NScheduleTask","对哨位是一个半小时类型排序时间1-9");

            //对哨位是45 类型的 时间ID在 1-7 之间进行选人，
            for (Sentry sentry1 : sentries_45) {
                for (Times times1 : timesList) {
                    int l = (int) (times1.getTimeID() + 0);
                    Soldier so;
                    switch (l) {
                        case 1://上午岗
                            so = chooseSoldierForOn(squadOn1.getSuqadId(), sentry1, times1);
                            if (so != null){
                                postRecordDao.insert(new PostRecord(null, sentry1.getSentry_id(), 2l, so.getSID(), dayofweek));
                                postRecordDao.insert(new PostRecord(null, sentry1.getSentry_id(), 3l, so.getSID(), dayofweek));
                                so.setGuardTimes(so.getGuardTimes() + 2);
                                soldierDao.update(so);
                            }
                            break;
                        case 4://中午岗
                            so = chooseSoldierForOn(squadOn2.getSuqadId(), sentry1, times1);
                            if (so != null){
                                postRecordDao.insert(new PostRecord(null, sentry1.getSentry_id(), 5l, so.getSID(), dayofweek));
                                so.setGuardTimes(so.getGuardTimes() + 1);
                                soldierDao.update(so);
                            }
                            break;
                        case 6://下午岗
                            so = chooseSoldierForOn(squadOn3.getSuqadId(), sentry1, times1);
                            if (so != null){
                                postRecordDao.insert(new PostRecord(null, sentry1.getSentry_id(), 7l, so.getSID(), dayofweek));
                                so.setGuardTimes(so.getGuardTimes() + 1);
                                soldierDao.update(so);
                            }
                            break;
                    }
                }
            }

            publishProgress("对哨位是半天类型排序 时间ID1-7","ok");
            LogUtils.e("NScheduleTask","对哨位是半天类型排序时间1-7");

            //下午18：30到20：00、20：00到22：00（除去603、503后共需10人，由中午岗除去大门口人员补入。
            List<PostRecord> noon = postRecordDao.queryBuilder()
                    .where(PostRecordDao.Properties.TimesID.eq(4l),
                            PostRecordDao.Properties.SentryID.notEq(2l),
                            PostRecordDao.Properties.SentryID.notEq(8l),
                            PostRecordDao.Properties.Dayofweek.eq(dayofweek))
                    .build().list();
            //新建集合 当士兵被分配后就从里面删除
            LinkedList<Soldier> noonSoldiers = new LinkedList<>();
            for (PostRecord postRecord : noon) {
                noonSoldiers.add(postRecord.getSoldier());
            }

            //给timeID为8的 45 类型哨位进行分配
            chooseNoonSoldierIntoTimes89(noonSoldiers, noon, 8l);

            publishProgress("给timeID为8的 45 类型哨位进行分配","ok");
            LogUtils.e("NScheduleTask","给timeID为8的 45 类型哨位进行分配");

            //给timeID为9的 45 类型哨位进行分配
            chooseNoonSoldierIntoTimes89(noonSoldiers, noon, 9l);

            publishProgress("给timeID为9的 45 类型哨位进行分配","ok");
            LogUtils.e("NScheduleTask","给timeID为9的 45 类型哨位进行分配");

            //从上午班里选择即进行排序
            noon = postRecordDao.queryBuilder()
                    .where(PostRecordDao.Properties.TimesID.eq(1l),
                            PostRecordDao.Properties.Dayofweek.eq(dayofweek),
                            PostRecordDao.Properties.SentryID.notIn(13l,14l))
                    .build().list();
            noonSoldiers.clear();
            for (PostRecord postRecord : noon) {
                noonSoldiers.add(postRecord.getSoldier());
            }
            //给时间ID为10，11分配人员
            chooseMorningSoldierIntoTimes1011(noonSoldiers, noon, 10l);
            chooseMorningSoldierIntoTimes1011(noonSoldiers, noon, 11l);

            publishProgress("给时间ID为10，11分配人员","ok");
            LogUtils.e("NScheduleTask","给时间ID为10，11分配人员");

            //从下午班里选择即进行排序
            noon = postRecordDao.queryBuilder()
                    .where(PostRecordDao.Properties.TimesID.eq(6l),
                            PostRecordDao.Properties.Dayofweek.eq(dayofweek))
                    .build().list();
            noonSoldiers.clear();
            for (PostRecord postRecord : noon) {
                noonSoldiers.add(postRecord.getSoldier());
            }

            //给时间ID为12，13分配人员
            chooseMorningSoldierIntoTimes1011(noonSoldiers, noon, 12l);
            chooseMorningSoldierIntoTimes1011(noonSoldiers, noon, 13l);

            publishProgress("给时间ID为12，13分配人员","ok");
            LogUtils.e("NScheduleTask","给时间ID为12，13分配人员");

            //给时间ID为14,15分配人员
            //查询派位记录表中的时间ID为8的所有记录
            noon = postRecordDao.queryBuilder().where(PostRecordDao.Properties.TimesID.eq(8l),
                    PostRecordDao.Properties.Dayofweek.eq(dayofweek)).build().list();
            noonSoldiers.clear();
            for (PostRecord postRecord : noon) {
                if (postRecord.getSentryID() == 3l || postRecord.getSentryID() == 5l || postRecord.getSentryID() == 6l || postRecord.getSentryID() == 11l || postRecord.getSentryID() == 12l || postRecord.getSentryID() == 13l || postRecord.getSentryID() == 14l){

                }else {
                    noonSoldiers.add(postRecord.getSoldier());
                }
            }
            //给时间ID为 14 的 分配人员
            chooseAfterNoonSoldierIntoTimes14(noonSoldiers, 14l);
            //查询 302 303 白天人员
            noon = postRecordDao.queryBuilder().where(PostRecordDao.Properties.TimesID.eq(1l),
                    PostRecordDao.Properties.SentryID.between(13l,15l),
                    PostRecordDao.Properties.Dayofweek.eq(dayofweek))
                    .build().list();
            //添加到集合里
            for (PostRecord postRecord : noon) {
                noonSoldiers.add(postRecord.getSoldier());
            }
            //查询时间ID为9并且是中午班的人员记录
            noon = postRecordDao.queryBuilder().where(PostRecordDao.Properties.TimesID.eq(9l),
                    PostRecordDao.Properties.SentryID.in(1l,4l,7l,9l,10l),
                    PostRecordDao.Properties.Dayofweek.eq(dayofweek))
                    .build().list();
            //添加到集合里
            for (PostRecord postRecord : noon) {
                noonSoldiers.add(postRecord.getSoldier());
            }

            //给时间ID为 15 的 分配人员
            chooseAfterNoonSoldierIntoTimes14(noonSoldiers, 15l);

            publishProgress("给时间ID为14,15分配人员","ok");
            LogUtils.e("NScheduleTask","给时间ID为14,15分配人员");

            List<Soldier> list = soldierDao.queryBuilder().where(SoldierDao.Properties.InUse.eq(SoldierInUseEnum.InUse.getCode())).build().list();
            for (Soldier soldier : list) {
                if (!soldier.getSquadID().equals(squadDuty.getSuqadId())){
                    soldier.setInUse(SoldierInUseEnum.NoUse.getCode());
                    soldierDao.update(soldier);
                }
            }
            publishProgress("人员重置完成","ok");
            LogUtils.e("NScheduleTask","人员重置完成");

            SystemClock.sleep(1500);

            publishProgress("结束","finish");
            LogUtils.e("NScheduleTask","结束");

        } else {
            List<Soldier> list = soldierDao.queryBuilder().where(SoldierDao.Properties.InUse.eq(SoldierInUseEnum.InUse.getCode())).build().list();
            for (Soldier soldier : list) {
                soldier.setInUse(SoldierInUseEnum.NoUse.getCode());
                soldierDao.update(soldier);
            }
            publishProgress("人员重置完成","ok");
            LogUtils.e("NScheduleTask","人员重置完成");

            //人数不够用，退出并提醒
            publishProgress("人员配置不合理","err");
            LogUtils.e("NScheduleTask","人员配置不合理");
        }


        return null;
    }

    private void chooseSoldierForDutyIn302(long squadID, Sentry sentry, Times time) {
        List<Soldier> list = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadID),
                SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode()),
                SoldierDao.Properties.Grade.notEq(SoldierCharacter.MONITOR.getCode()))
                .build().list();
        List<Soldier> temp = new ArrayList<>();
        for (Soldier soldier : list) {
            if (soldier.canGuard(sentry,true)){
                temp.add(soldier);
            }
        }

        if (temp.size() > 0) {
            Soldier so;
            Collections.sort(temp,new SoldierComparator());
            List<Soldier> bests = new ArrayList<>();
            for (Soldier soldier : temp) {
                if (soldier.getSentryGroup().size() == temp.get(0).getSentryGroup().size()){
                    bests.add(soldier);
                }
            }
            if (bests.size() > 0){
                Collections.sort(bests,new SoldierComparator());
                int index = dayofweek-1;
                if (index<bests.size()){
                    so = bests.get(index);
                }else {
                    int i = index % bests.size();
                    so = bests.get(i);
                }
            }else{
                so = temp.get(0);
            }
            postRecordDao.insert(new PostRecord(null, sentry.getSentry_id(), time.getTimeID(), so.getSID(), dayofweek));
            so.setInUse(SoldierInUseEnum.InUse.getCode());
            so.setGuardTimes(so.getGuardTimes() + 1);
            soldierDao.update(so);

            DutySoldierRecord dutySoldierRecord = new DutySoldierRecord(null,so.getSID(),sentry.getSentry_id(),1,dayofweek);
            dutySoldierDao.insert(dutySoldierRecord);
        }else {
            List<DutySoldierRecord> dutyList = dutySoldierDao.queryBuilder().orderAsc(DutySoldierRecordDao.Properties.Counts).build().list();
            List<DutySoldierRecord> tempDuty = new ArrayList<>();
            Soldier so;
            for (DutySoldierRecord dutySoldierRecord : dutyList) {
                Soldier sol =  dutySoldierRecord.getSoldier();
                if (sol.canGuard(sentry,true)){
                    tempDuty.add(dutySoldierRecord);
                }
            }
            if (tempDuty.size() > 0){
                Collections.sort(tempDuty,new DutySoldierRecordComparator());
                so = tempDuty.get(0).getSoldier();
                postRecordDao.insert(new PostRecord(null, sentry.getSentry_id(), time.getTimeID(), so.getSID(), dayofweek));
                so.setInUse(SoldierInUseEnum.InUse.getCode());
                so.setGuardTimes(so.getGuardTimes() + 1);
                soldierDao.update(so);

                tempDuty.get(0).setCounts(tempDuty.get(0).getCounts()+1);
                dutySoldierDao.update(tempDuty.get(0));
            }

        }
    }

    private void chooseAfterNoonSoldierIntoTimes14(List<Soldier> onFirst, long timeID) {
        //先给15类分配
        for (Sentry sentry1 : sentries_15) {
            int l = (int) (sentry1.getSentry_id() + 0);
            switch (l) {
                case 2:
                    chooseAfterNoonSoldier(onFirst, sentry1, timeID);
                    break;
                case 8:
                    chooseAfterNoonSoldier(onFirst, sentry1, timeID);
                    break;
            }
        }
        //给45 类哨位分配人员
        for (Sentry sentry1 : sentries_45) {
            int l = (int) (sentry1.getSentry_id() + 0);
            switch (l) {
                case 1:
                    chooseAfterNoonSoldier(onFirst, sentry1, timeID);
                    break;
                case 4:
                    chooseAfterNoonSoldier(onFirst, sentry1, timeID);
                    break;
                case 7:
                    chooseAfterNoonSoldier(onFirst, sentry1, timeID);
                    break;
                case 9:
                    chooseAfterNoonSoldier(onFirst, sentry1, timeID);
                    break;
                case 10:
                    chooseAfterNoonSoldier(onFirst, sentry1, timeID);
                    break;
            }
        }
    }

    private void chooseAfterNoonSoldier(List<Soldier> onFirst, Sentry sentry1, long timeID) {
        Soldier so;
        List<Soldier> temp = new ArrayList<>();
        if (onFirst.size() > 0) {
            for (Soldier soldier : onFirst) {
                if (soldier.canGuard(sentry1,true)){
                    temp.add(soldier);
                }
            }
            if (temp.size()>0){
                Collections.sort(temp,new SoldierComparator());
                List<Soldier> bests = new ArrayList<>();
                int index = dayofweek-1;
                for (Soldier soldier : temp) {
                    if (soldier.getSentryGroup().size() == temp.get(0).getSentryGroup().size()){
                        bests.add(soldier);
                    }
                }
                if (bests.size() > 0){
                    Collections.sort(bests,new SoldierComparator());
                    if (index<bests.size()){
                        so = bests.get(index);
                    }else {
                        int i = index % bests.size();
                        so = bests.get(i);
                    }
                }else {
                    so = temp.get(0);
                }
                LogUtils.e("NScheduleTask","chooseAfterNoonSoldier timeID:"+timeID+" sentry:"+sentry1.getSentry_name()+temp.size());
                postRecordDao.insert(new PostRecord(null, sentry1.getSentry_id(), timeID, so.getSID(), dayofweek));
                so.setGuardTimes(so.getGuardTimes() + 1);
                soldierDao.update(so);
                onFirst.remove(so);
            }else {
                Times time = timesDaoDao.queryBuilder().where(TimesDao.Properties.TimeID.eq(timeID)).unique();
                if (hasRest) {
                    chooseSoldierForRest(squadRest.getSuqadId(), sentry1, time);
                } else {
                    chooseSoldierForDuty(squadDuty.getSuqadId(), sentry1, time);
                }
            }

        }else {
            Times time = timesDaoDao.queryBuilder().where(TimesDao.Properties.TimeID.eq(timeID)).unique();
            if (hasRest) {
                chooseSoldierForRest(squadRest.getSuqadId(), sentry1, time);
            } else {
                chooseSoldierForDuty(squadDuty.getSuqadId(), sentry1, time);
            }
        }
    }

    //将上午班的人员分配给时间ID为10-11的哨位
    private void chooseMorningSoldierIntoTimes1011(LinkedList<Soldier> noonSoldiers, List<PostRecord> noon, long timeID){
        //先给15类分配
        for (Sentry sentry1 : sentries_15) {
            int l = (int) (sentry1.getSentry_id() + 0);
            switch (l) {
                case 2:
                    chooseMorningSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
                case 8:
                    chooseMorningSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
            }
        }
        //给45 类哨位分配人员
        for (Sentry sentry1 : sentries_45) {
            int l = (int) (sentry1.getSentry_id() + 0);
            switch (l) {
                case 1:
                    chooseMorningSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
                case 4:
                    chooseMorningSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
                case 7:
                    chooseMorningSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
                case 9:
                    chooseMorningSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
                case 10:
                    chooseMorningSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
            }
        }
    }
    private void chooseMorningSoldier(LinkedList<Soldier> noonSoldiers, List<PostRecord> noon, Sentry sentry1, long timeID) {
        Soldier so;
        if (noonSoldiers.size() >0){
            List<Soldier> temp = new ArrayList<>();
            for (Soldier noonSoldier : noonSoldiers) {
                if (noonSoldier.canGuard(sentry1,true)){
                    temp.add(noonSoldier);
                }
            }
            LogUtils.e("NScheduleTask","chooseNoonSoldier timeID:"+timeID+temp.size());
            if (temp.size() > 0) {
                Collections.sort(temp,new SoldierComparator());
                List<Soldier> bests = new ArrayList<>();
                int index = dayofweek-1;
                for (Soldier soldier : temp) {
                    if (soldier.getSentryGroup().size() == temp.get(0).getSentryGroup().size()){
                        bests.add(soldier);
                    }
                }
                if (bests.size() > 0){
                    Collections.sort(bests,new SoldierComparator());
//                    if (index<bests.size()){
//                        so = bests.get(index);
//                    }else {
//                        int i = index % bests.size();
//                        so = bests.get(i);
//                    }
                    so = bests.get(0);
                }else {
                    so = temp.get(0);
                }

                postRecordDao.insert(new PostRecord(null, sentry1.getSentry_id(), timeID, so.getSID(), dayofweek));
                so.setGuardTimes(so.getGuardTimes() + 1);
                soldierDao.update(so);
                noonSoldiers.remove(so);
            } else {
                Times time = timesDaoDao.queryBuilder().where(TimesDao.Properties.TimeID.eq(timeID)).build().unique();
                if (hasRest){
                    so = chooseSoldierForOnFromRest(squadRest.getSuqadId(), sentry1, time);
                    if (so == null){
                        chooseSoldierForOnFromDuty(squadDuty.getSuqadId(),sentry1,time);
                    }
                }else {
                    chooseSoldierForOnFromDuty(squadDuty.getSuqadId(),sentry1,time);
                }
            }
        }else {
            Times time = timesDaoDao.queryBuilder().where(TimesDao.Properties.TimeID.eq(timeID)).unique();
            if (hasRest) {
                chooseSoldierForRest(squadRest.getSuqadId(), sentry1, time);
            } else {
                chooseSoldierForDuty(squadDuty.getSuqadId(), sentry1, time);
            }
        }

    }

    //选择补岗班的人员进行分配
    private void chooseSoldierForRest(long squadID, Sentry sentry, Times times) {
        List<Soldier> list = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadID),
                SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode()))
                .build().list();
        List<Soldier> zerolist = new ArrayList<>();
        List<Soldier> temp = new ArrayList<>();
        for (Soldier soldier : list) {
            if (soldier.canGuard(sentry,true)) {
                if (soldier.getGuardTimes() == 0){
                    zerolist.add(soldier);
                }
                temp.add(soldier);
            }
        }
        if (zerolist.size() > 0){
            Collections.sort(temp,new SoldierComparator());
            Soldier so = temp.get(0);
            postRecordDao.insert(new PostRecord(null, sentry.getSentry_id(), times.getTimeID(), so.getSID(), dayofweek));
            so.setInUse(SoldierInUseEnum.InUse.getCode());
            so.setGuardTimes(so.getGuardTimes() + 1);
            soldierDao.update(so);
        }else if (temp.size() > 0 && zerolist.size() <0) {
            Collections.sort(temp,new SoldierComparator());
            Soldier so = temp.get(0);
            postRecordDao.insert(new PostRecord(null, sentry.getSentry_id(), times.getTimeID(), so.getSID(), dayofweek));
            so.setInUse(SoldierInUseEnum.InUse.getCode());
            so.setGuardTimes(so.getGuardTimes() + 1);
            soldierDao.update(so);
        }else {
            chooseSoldierForDuty(squadID, sentry, times);
        }
    }

    //将中午岗的人员分配给时间ID为8-9的哨位内
    private void chooseNoonSoldierIntoTimes89(LinkedList<Soldier> noonSoldiers, List<PostRecord> noon, long timeID) {
        for (Sentry sentry1 : sentries_45) {
            int l = (int) (sentry1.getSentry_id() + 0);
            switch (l) {
                case 1://501
                    chooseNoonSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
                case 4://505
                    chooseNoonSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
                case 7://601
                    chooseNoonSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
                case 9://604
                    chooseNoonSoldier(noonSoldiers, noon, sentry1, timeID);
                    break;
                case 10://605
                    chooseNoonMonitor(sentry1, timeID);
                    break;
            }
        }
    }

    //已分配好的中午岗人员选择
    private void chooseNoonSoldier(LinkedList<Soldier> noonSoldiers, List<PostRecord> noon, Sentry sentry1, long timeID) {
        Soldier so;
        List<Soldier> temp = new ArrayList<>();
        if (noonSoldiers.size() > 0){
            for (Soldier noonSoldier : noonSoldiers) {
                if (noonSoldier.canGuard(sentry1,true)){
                    temp.add(noonSoldier);
                }
            }
            squadOn2.resetSoldiers();
            for (Soldier soldier : squadOn2.getSoldiers()) {
                if (soldier.canGuard(sentry1,true) && soldier.getInUse().equals(SoldierInUseEnum.NoUse.getCode())){
                    temp.add(soldier);
                    LogUtils.e("NScheduleTask","存在可用未战士兵"+soldier.getSName());
                }
            }
            LogUtils.e("NScheduleTask","chooseNoonSoldier timeID:"+timeID+temp.size());
            if (temp.size() > 0) {
                Collections.sort(temp,new SoldierComparator());
                List<Soldier> bests = new ArrayList<>();
                int index = dayofweek-1;
                for (Soldier soldier : temp) {
                    if (soldier.getSentryGroup().size() == temp.get(0).getSentryGroup().size()){
                        bests.add(soldier);
                    }
                }
                if (bests.size() > 0){
                    Collections.sort(bests,new SoldierComparator());
//                    if (index<bests.size()){
//                        so = bests.get(index);
//                    }else {
//                        int i = index % bests.size();
//                        so = bests.get(i);
//                    }
                    so = bests.get(0);
                }else {
                    so = temp.get(0);
                }

                postRecordDao.insert(new PostRecord(null, sentry1.getSentry_id(), timeID, so.getSID(), dayofweek));
                so.setGuardTimes(so.getGuardTimes() + 1);
                soldierDao.update(so);
                noonSoldiers.remove(so);
            } else {
                Times time = timesDaoDao.queryBuilder().where(TimesDao.Properties.TimeID.eq(timeID)).build().unique();
                if (hasRest){
                    so = chooseSoldierForOnFromRest(squadRest.getSuqadId(), sentry1, time);
                    if (so == null){
                        chooseSoldierForOnFromDuty(squadDuty.getSuqadId(),sentry1,time);
                    }
                }else {
                    chooseSoldierForOnFromDuty(squadDuty.getSuqadId(),sentry1,time);
                }
            }
        } else {
            Times time = timesDaoDao.queryBuilder().where(TimesDao.Properties.TimeID.eq(timeID)).build().unique();
            if (hasRest){
                so = chooseSoldierForOnFromRest(squadRest.getSuqadId(), sentry1, time);
                if (so == null){
                    chooseSoldierForOnFromDuty(squadDuty.getSuqadId(),sentry1,time);
                }
            }else {
                chooseSoldierForOnFromDuty(squadDuty.getSuqadId(),sentry1,time);
            }
        }
    }
    //选择中午班的班长
    private void chooseNoonMonitor(Sentry sentry1, long timeID){
        List<Soldier> monitors = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadOn2.getSuqadId()),
                SoldierDao.Properties.Grade.eq(SoldierCharacter.MONITOR.getCode()))
                .build().list();
        List<Soldier> temp = new ArrayList<>();
        for (Soldier monitor : monitors) {
            if (monitor.canGuard(sentry1,true)){
                temp.add(monitor);
            }
        }
        Soldier so;
        if (temp.size() > 0){
            Collections.sort(temp,new SoldierComparator());
            so = temp.get(0);
            postRecordDao.insert(new PostRecord(null, sentry1.getSentry_id(), timeID, so.getSID(), dayofweek));
            so.setGuardTimes(so.getGuardTimes() + 1);
            soldierDao.update(so);
            monitors.remove(so);
        }
    }

    //对哨位为一个半小时的进行选人，将时间ID为1，2，3，的写入数据库
    private void chooseSoldierForSentry15In123(Sentry sentryDB, List<Soldier> soldier_Morning) {
        //遍历每一个时间段，按时间顺序进行排序
        for (Times timesDB : timesList) {
            //前三个时间段 给哨位类型15 安排人员
            if (timesDB.getTimeID() <= 3) {
                int l = (int) (timesDB.getTimeID() + 0);
                Soldier so = null;
                switch (l) {
                    case 1:
                        so = chooseSoldierForOn(squadOn1.getSuqadId(), sentryDB, timesDB);
                        soldier_Morning.add(so);
                        break;
                    case 2:
                        so = chooseSoldierForOn(squadOn2.getSuqadId(), sentryDB, timesDB);
                        soldier_Morning.add(so);
                        break;
                    case 3:
                        so = chooseSoldierForOn(squadOn3.getSuqadId(), sentryDB, timesDB);
                        soldier_Morning.add(so);
                        break;
                }
            }
        }
    }

    //一个半小时哨位 时间ID 4-9的进行人员分配 利用时间ID 1-3 的分配结果
    private void chooseSoldierForSentry15In429(Sentry sentryDB, List<Soldier> soldier_Morning_1, List<Soldier> soldier_Morning_2) {
        for (Times times : timesList) {
            Soldier so = null;
            int l = (int) (times.getTimeID() + 0);
            switch (l) {
                case 4:
                    so = soldier_Morning_2.get(0);
                    postRecordDao.insert(new PostRecord(null, sentryDB.getSentry_id(), times.getTimeID(), so.getSID(), dayofweek));
                    so.setGuardTimes(so.getGuardTimes() + 1);
                    soldierDao.update(so);
                    break;
                case 5:
                    so = soldier_Morning_2.get(1);
                    postRecordDao.insert(new PostRecord(null, sentryDB.getSentry_id(), times.getTimeID(), so.getSID(), dayofweek));
                    so.setGuardTimes(so.getGuardTimes() + 1);
                    soldierDao.update(so);
                    break;
                case 6:
                    so = soldier_Morning_2.get(2);
                    postRecordDao.insert(new PostRecord(null, sentryDB.getSentry_id(), times.getTimeID(), so.getSID(), dayofweek));
                    so.setGuardTimes(so.getGuardTimes() + 1);
                    soldierDao.update(so);
                    break;
                case 7:
                    so = soldier_Morning_1.get(0);
                    postRecordDao.insert(new PostRecord(null, sentryDB.getSentry_id(), times.getTimeID(), so.getSID(), dayofweek));
                    so.setGuardTimes(so.getGuardTimes() + 1);
                    soldierDao.update(so);
                    break;
                case 8:
                    so = soldier_Morning_1.get(1);
                    postRecordDao.insert(new PostRecord(null, sentryDB.getSentry_id(), times.getTimeID(), so.getSID(), dayofweek));
                    so.setGuardTimes(so.getGuardTimes() + 1);
                    soldierDao.update(so);
                    break;
                case 9:
                    so = soldier_Morning_1.get(2);
                    postRecordDao.insert(new PostRecord(null, sentryDB.getSentry_id(), times.getTimeID(), so.getSID(), dayofweek));
                    so.setGuardTimes(so.getGuardTimes() + 1);
                    soldierDao.update(so);
                    break;

            }
        }
    }

    //上岗班选人
    private Soldier chooseSoldierForOn(long squadID, Sentry sentry, Times time) {
        List<Soldier> list = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadID),
                SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode()))
                .build().list();
        List<Soldier> temp = new ArrayList<>();
        for (Soldier soldier : list) {
            if (soldier.canGuard(sentry)) {
                temp.add(soldier);
            }
        }
        if (temp.size() > 0) {
            Soldier so;
            Collections.sort(temp,new SoldierComparator());
            List<Soldier> bests = new ArrayList<>();
            int index = dayofweek-1;
            for (Soldier soldier : temp) {
                if (soldier.getSentryGroup().size() == temp.get(0).getSentryGroup().size()){
                    bests.add(soldier);
                }
            }
            if (bests.size() > 0){
                Collections.sort(bests,new SoldierComparator());
                if (index<bests.size()){
                    so = bests.get(index);
                }else {
                    int i = index % bests.size();
                    so = bests.get(i);
                }
            }else {
                so = temp.get(0);
            }

            postRecordDao.insert(new PostRecord(null, sentry.getSentry_id(), time.getTimeID(), so.getSID(), dayofweek));
            so.setInUse(SoldierInUseEnum.InUse.getCode());
            so.setGuardTimes(so.getGuardTimes() + 1);
            soldierDao.update(so);
            return so;
        } else {
            Soldier so;
            //此处可能出现无限递归，但是之前做过判断人员是否够用后才加入，所以不会有问题
            if (hasRest){
                so = chooseSoldierForOnFromRest(squadRest.getSuqadId(), sentry, time);
                if (so == null){
                    so = chooseSoldierForOnFromDuty(squadDuty.getSuqadId(),sentry,time);
                }
                return so;
            }else {
                return chooseSoldierForOnFromDuty(squadDuty.getSuqadId(),sentry,time);
            }
        }
    }
    public Soldier chooseSoldierForOnFromRest(long squadID, Sentry sentry, Times time){
        List<Soldier> list = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadID),
                SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode()))
                .build().list();
        List<Soldier> temp = new ArrayList<>();
        for (Soldier soldier : list) {
            if (soldier.canGuard(sentry)) {
                temp.add(soldier);
            }
        }
        if (temp.size() > 0) {
            Soldier so;
            Collections.sort(temp,new SoldierComparator());
            int index = dayofweek-1;
            if (index<temp.size()){
                so = temp.get(index);
            }else {
                int i = index % temp.size();
                so = temp.get(i);
            }
            postRecordDao.insert(new PostRecord(null, sentry.getSentry_id(), time.getTimeID(), so.getSID(), dayofweek));
            so.setInUse(SoldierInUseEnum.InUse.getCode());
            so.setGuardTimes(so.getGuardTimes() + 1);
            soldierDao.update(so);
            return so;
        }else {
            return null;
        }
    }
    public Soldier chooseSoldierForOnFromDuty(long squadID, Sentry sentry, Times time){
        List<Soldier> list = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadID),
                SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode()))
                .build().list();
        List<Soldier> temp = new ArrayList<>();
        for (Soldier soldier : list) {
            if (soldier.canGuard(sentry)) {
                temp.add(soldier);
            }
        }
        if (temp.size() > 0) {
            Soldier so;
            Collections.sort(temp,new SoldierComparator());
            int index = dayofweek-1;
            if (index<temp.size()){
                so = temp.get(index);
            }else {
                int i = index % temp.size();
                so = temp.get(i);
            }
            postRecordDao.insert(new PostRecord(null, sentry.getSentry_id(), time.getTimeID(), so.getSID(), dayofweek));
            so.setInUse(SoldierInUseEnum.InUse.getCode());
            so.setGuardTimes(so.getGuardTimes() + 1);
            soldierDao.update(so);
            return so;
        }else {
            return null;
        }
    }

    //值班版选人
    private void chooseSoldierForDuty(long squadID, Sentry sentry, Times time) {
        List<Soldier> list = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadID),
                SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode()))
                .build().list();
        List<PostRecord> l = postRecordDao.queryBuilder()
                .where(PostRecordDao.Properties.SentryID.in(13l, 14l),
                        PostRecordDao.Properties.TimesID.eq(1l),
                        PostRecordDao.Properties.Dayofweek.eq(dayofweek)).build().list();
        Set<Long> set = new HashSet<>();
        for (PostRecord postRecord : l) {
            set.add(postRecord.getSoldier().getSID());
        }
        List<Soldier> temp = new ArrayList<>();
        for (Soldier soldier : list) {
            if (soldier.canGuard(sentry,true)) {
                if (set.add(soldier.getSID())){
                    temp.add(soldier);
                }
            }
        }
        if (temp.size() > 0) {
            Collections.sort(temp,new SoldierComparator());
            Soldier so = temp.get(0);
            postRecordDao.insert(new PostRecord(null, sentry.getSentry_id(), time.getTimeID(), so.getSID(), dayofweek));
            so.setInUse(SoldierInUseEnum.InUse.getCode());
            so.setGuardTimes(so.getGuardTimes() + 1);
            soldierDao.update(so);
        }
    }

    //将值班版班长选入下午6点半到8点的607
    private void chooseSoldierForDutyIn607(long squadID, Sentry sentry, Times time) {
        List<Soldier> list = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadID),
                SoldierDao.Properties.Grade.eq(SoldierCharacter.MONITOR.getCode()))
                .build().list();
        List<Soldier> temp = new ArrayList<>();
        for (Soldier soldier : list) {
            if (soldier.canGuard(sentry,true)) {
                temp.add(soldier);
            }
        }
        if (temp.size() > 0) {
            Collections.sort(temp,new SoldierComparator());
            Soldier so = temp.get(0);
            postRecordDao.insert(new PostRecord(null, sentry.getSentry_id(), time.getTimeID(), so.getSID(), dayofweek));
            so.setInUse(SoldierInUseEnum.InUse.getCode());
            so.setGuardTimes(so.getGuardTimes() + 2);
            soldierDao.update(so);
        }
    }

    //验证上岗班人员是否够用
    private boolean checkSoldierForSentry(List<Sentry> sentries, int type) {
        int size = sentries.size();
        size = size * 2;
        //获取上午班可用人员集合
        List<Soldier> sOn1 = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadOn1.getSuqadId()),
                SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode())).build().list();
        //获取中午班可用人员集合
        List<Soldier> sOn2 = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadOn2.getSuqadId()),
                SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode())).build().list();
        //获取下午班可用人员集合
        List<Soldier> sOn3 = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadOn3.getSuqadId()),
                SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode())).build().list();
        Set<Soldier> set1 = new HashSet<>();
        Set<Soldier> set2 = new HashSet<>();
        Set<Soldier> set3 = new HashSet<>();

        for (Soldier soldier : sOn1) {
            for (Sentry sentry1 : sentries) {
                if (soldier.canGuard(sentry1)) {//检测到可以上刚，加入集合，不可重复加入所以用set
                    set1.add(soldier);
                }
            }
        }
        if (set1.size() < size) {
            if (!hasRest) {
                List<Soldier> sDuty = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadDuty.getSuqadId()),
                        SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode())).build().list();
                for (Soldier soldier : sDuty) {
                    for (Sentry sentry : sentries) {
                        if (soldier.canGuard(sentry)) {//检测到可以上刚，加入集合，不可重复加入所以用set
                            set1.add(soldier);
                        }
                    }
                }
                if (set1.size() < size) {
                    return false;
                }
            } else {
                //补岗班人员存在 加入进行检测
                List<Soldier> sRest = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadRest.getSuqadId()),
                        SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode())).build().list();
                for (Soldier soldier : sRest) {
                    for (Sentry sentry1 : sentries) {
                        if (soldier.canGuard(sentry1)) {//检测到可以上刚，加入集合，不可重复加入所以用set
                            set1.add(soldier);
                        }
                    }
                }
                if (set1.size() < size) {
                    return false;
                }
            }
        }


        for (Soldier soldier : sOn2) {
            for (Sentry sentry1 : sentries) {
                if (soldier.canGuard(sentry1)) {
                    set2.add(soldier);
                }
            }
        }
        if (set2.size() < size) {
            if (!hasRest) {
                List<Soldier> sDuty = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadDuty.getSuqadId()),
                        SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode())).build().list();
                for (Soldier soldier : sDuty) {
                    for (Sentry sentry : sentries) {
                        if (soldier.canGuard(sentry)) {//检测到可以上刚，加入集合，不可重复加入所以用set
                            set2.add(soldier);
                        }
                    }
                }
                if (set2.size() < size) {
                    return false;
                }
            } else {
                //补岗班人员存在 加入进行检测
                List<Soldier> sRest = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadRest.getSuqadId()),
                        SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode())).build().list();
                for (Soldier soldier : sRest) {
                    for (Sentry sentry1 : sentries) {
                        if (soldier.canGuard(sentry1)) {//检测到可以上刚，加入集合，不可重复加入所以用set
                            set2.add(soldier);
                        }
                    }
                }
                if (set2.size() < size) {
                    return false;
                }
            }
        }


        for (Soldier soldier : sOn3) {
            for (Sentry sentry1 : sentries) {
                if (soldier.canGuard(sentry1)) {
                    set3.add(soldier);
                }
            }
        }
        if (set3.size() < size) {
            if (!hasRest) {
                List<Soldier> sDuty = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadDuty.getSuqadId()),
                        SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode())).build().list();
                for (Soldier soldier : sDuty) {
                    for (Sentry sentry : sentries) {
                        if (soldier.canGuard(sentry)) {//检测到可以上刚，加入集合，不可重复加入所以用set
                            set3.add(soldier);
                        }
                    }
                }
                if (set3.size() < size) {
                    return false;
                }
            } else {
                //补岗班人员存在 加入进行检测
                List<Soldier> sRest = soldierDao.queryBuilder().where(SoldierDao.Properties.SquadID.eq(squadRest.getSuqadId()),
                        SoldierDao.Properties.InUse.eq(SoldierInUseEnum.NoUse.getCode())).build().list();
                for (Soldier soldier : sRest) {
                    for (Sentry sentry1 : sentries) {
                        if (soldier.canGuard(sentry1)) {//检测到可以上刚，加入集合，不可重复加入所以用set
                            set3.add(soldier);
                        }
                    }
                }
                if (set3.size() < size) {
                    return false;
                }
            }
        }

        return true;
    }
}

